home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / linux / testdisk_floppy.sh next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2002-11-24  |  3.9 KB  |  205 lines

  1. #!/bin/sh
  2. FLOPPY=/dev/fd0
  3. IMG_FLOPPY=testdisk.floppy
  4. MNT_FLOPPY=/mnt/testdisk
  5. MNT_INITRD=/mnt/initrd
  6. KERNEL=/boot/vmlinuz-2.4.18-small
  7. MY_DIR=$PWD
  8. TERMLINUX=/usr/share/terminfo/l/linux
  9. TESTDISK=$PWD/src/testdisk_static
  10.  
  11. BUSYBOX=busybox-0.60.4
  12. UCLIBC=uClibc-0.9.15
  13. UCLIBCDIR=/uclibc
  14.  
  15. # Installation of uclibc
  16. if [ ! -e /uclibc/bin/i386-uclibc-gcc ]
  17. then
  18.  
  19. if [ ! -e $UCLIBC.tar.bz2 ]
  20. then
  21.   echo "Please get $UCLIBC.tar.bz2 at http://www.uclibc.org and put it in $MY_DIR directory"
  22.   exit 1
  23. fi
  24.  
  25. #tar xjf $UCLIBC.tar.bz2
  26. if [ ! -d $UCLIBCDIR ]
  27. then 
  28.   mkdir $UCLIBCDIR
  29.   if [ ! -d $UCLIBCDIR ]
  30.   then 
  31.     echo "Creation of $UCLIBCDIR failed"
  32.     exit 1
  33.   fi
  34. fi
  35.  
  36. if [ ! -d /usr/src/linux ]
  37. then
  38.   if [ -d /usr/src/linux-2.4 ]
  39.   then
  40.     ln -s /usr/src/linux-2.4 /usr/src/linux
  41.   else
  42.     echo "/usr/src/linux or /usr/src/linux-2.4 not found. Please install kernel source"
  43.     exit 1
  44.   fi
  45. fi
  46.  
  47. cd $UCLIBC
  48. echo "DEVEL_PREFIX = $UCLIBCDIR" > Config
  49. grep -v "^DEVEL_PREFIX = " ./extra/Configs/Config.i386 >> Config
  50. make && make install
  51. cd ..
  52. fi
  53.  
  54. # Installation of Busybox
  55. if [ ! -e $BUSYBOX/busybox ]
  56. then
  57.  
  58. if [ ! -e $BUSYBOX.tar.bz2 ]
  59. then
  60.   echo "Please get $BUSYBOX.tar.bz2 at http://www.busybox.net and put it in $MY_DIR directory"
  61.   exit 1
  62. fi
  63.  
  64. tar xjf $BUSYBOX.tar.bz2
  65. cd $BUSYBOX
  66. echo "#define BB_FEATURE_INSTALLER" >> Config.h
  67. echo "#define BB_FEATURE_USE_TERMIOS" >> Config.h
  68. make CC=$UCLIBCDIR/bin/i386-uclibc-gcc
  69. cd ..
  70. fi
  71.  
  72. if [ ! -e $KERNEL ]
  73. then
  74.   echo "Please redefine KERNEL in the script"
  75.   exit 1
  76. fi
  77.  
  78. if [ ! -e $TERMLINUX ]
  79. then
  80.   echo "Please redefine TERMLINUX in the script"
  81. fi
  82.  
  83. if [ ! -e $TESTDISK ]
  84. then
  85.   cd src
  86.   make linuxstatic
  87.   if [ ! -e $TESTDISK ]
  88.   then
  89.     exit 1
  90.   fi
  91. fi
  92.  
  93.  
  94.  
  95. if [ ! -d $MNT_FLOPPY ]
  96. then 
  97.   mkdir $MNT_FLOPPY
  98.   if [ ! -d $MNT_FLOPPY ]
  99.   then 
  100.     echo "Creation of $MNT_FLOPPY failed"
  101.     exit 1
  102.   fi
  103. fi
  104.  
  105. if [ ! -d $MNT_INITRD ]
  106. then 
  107.   mkdir $MNT_INITRD
  108.   if [ ! -d $MNT_INITRD ]
  109.   then 
  110.     echo "Creation of $MNT_INITRD failed"
  111.     exit 1
  112.   fi
  113. fi
  114.  
  115. mkfs -t vfat -n "TESTDISK" $FLOPPY
  116. syslinux $FLOPPY
  117. dd if=$FLOPPY of=$IMG_FLOPPY bs=512k
  118.  
  119.  
  120. mount -o loop $IMG_FLOPPY $MNT_FLOPPY
  121.  
  122. cp $KERNEL $MNT_FLOPPY/vmlinuz
  123.  
  124. cat << EOF > $MNT_FLOPPY/syslinux.cfg
  125. default testdisk
  126. display testdisk.msg
  127.  
  128. label testdisk
  129.   kernel vmlinuz
  130.   append initrd=initrd.gz root=/dev/fd0
  131. EOF
  132.  
  133. cat << EOF > $MNT_FLOPPY/testdisk.msg
  134. Welcome to TestDisk rescue boot disk
  135. EOF
  136.  
  137. dd if=/dev/zero of=initrd bs=1k count=4096
  138.  
  139. mke2fs -Fm0 initrd 4096
  140. mount -o loop initrd $MNT_INITRD
  141. cd $MNT_INITRD
  142. mkdir dev etc lib mnt mnt/fd0 proc bin sbin usr usr/bin usr/lib usr/sbin var var/log var/db var/run var/state .$UCLIBCDIR
  143.  
  144. cd dev
  145. mknod -m 660 console c 5 1
  146. mknod -m 664 fd0 b 2 0
  147. mknod -m 666 null c 1 3
  148. mknod -m 640 ram b 1 1
  149. mknod -m 666 tty c 5 0
  150. mknod -m 600 tty0 c 4 0
  151. mknod -m 666 zero c 1 5
  152. mknod -m 660 hda b 3 0
  153. mknod -m 660 hdb b 3 64
  154. mknod -m 660 hdc b 22 0
  155. mknod -m 660 hdd b 22 64
  156. mknod -m 660 sda b 8 0
  157. mknod -m 660 sdb b 8 16
  158. mknod -m 660 sdc b 8 32
  159. mknod -m 660 sdd b 8 48
  160.  
  161. cd $MNT_INITRD/bin
  162. ln -s busybox sh
  163.  
  164. cd $MY_DIR
  165. tar cvf - $BUSYBOX/busybox | tar x -C $MNT_INITRD/bin
  166.  
  167. cd $UCLIBCDIR
  168. tar cvf - lib/ld-uClibc* lib/libc.so* lib/libuClibc* | tar x -C $MNT_INITRD/$UCLIBCDIR
  169.  
  170. cat << EOF > $MNT_INITRD/linuxrc
  171. #!/bin/sh
  172. PATH="/bin:/sbin:/usr/bin:/usr/sbin"
  173. TERM=linux
  174. ignoreeof=10
  175. no_exit_on_failed_exec=yes
  176. export PATH TERM ignoreeof
  177. umask 022
  178. /bin/busybox mount -t proc /proc /proc
  179. /bin/busybox -install -s
  180. mount -t vfat /dev/fd0 /mnt/fd0
  181. [ -f /mnt/fd0/testdisk.ini ] && cat /mnt/fd0/testdisk.ini > /testdisk.ini
  182. [ -f /testdisk.ini ] && chmod 777 /testdisk.ini
  183. [ -f /testdisk.ini ] && /testdisk.ini
  184. exec sh
  185. EOF
  186. chmod 777 $MNT_INITRD/linuxrc
  187.  
  188. cp $TERMLINUX $MNT_INITRD
  189. cp $TESTDISK $MNT_INITRD
  190.  
  191. cat << EOF > $MNT_INITRD/testdisk.ini
  192. #!/bin/sh
  193. export TERMINFO=/
  194. cd /mnt/fd0
  195. /testdisk_static
  196. EOF
  197. chmod 777 $MNT_INITRD/testdisk.ini
  198.  
  199. cd $MY_DIR
  200. umount $MNT_INITRD
  201. gzip -9f initrd
  202. cp initrd.gz $MNT_FLOPPY
  203. umount $MNT_FLOPPY
  204. dd if=testdisk.floppy of=$FLOPPY bs=512k
  205.